import { useCallback } from "react";
import { useDispatch, useSelector } from "react-redux";
import Creator from "../store/actions";
// 引入api
import LabelsApi from "../api/labels";

export const useTypes = () => {
    // 获取全部父类型数据
    const types = useSelector(state => {
        return state.allType
    })
    const dispatch = useDispatch();
    const { curPage, eachPage } = types;
    // 操作状态的行为

    // 获取所有子类型
    const getTypes = useCallback(async () => {
        const data = await LabelsApi.getAll({ curPage, eachPage })
        dispatch(Creator.getTypes(data));
    }, [curPage, eachPage, dispatch]);
    

    return [types, {getTypes}]

}